const funcj2j = require('./functions/jsonp-to-json');
const funcj2s = require('./functions/json-to-mysql');
const fs = require('fs');

https://finance.sina.com.cn/realstock/company/sh000001/nc.shtml
function demo () {
    var url = 'https://quotes.sina.cn/cn/api/jsonp_v2.php/var%20_sh000001_30_1741247013455=/CN_MarketDataService.getKLineData?symbol=sh000001&scale=60&ma=no&datalen=1023'
    fetch(url).then( (response) => {
        response.text().then(results => {

            var ouputs = funcj2j.transform(results)

            // ouputs { "day": "2024-02-07 15:00:00", "open": "2814.342", "high": "2829.696", "low": "2799.332", "close": "2829.696", "volume": "10586678500", "amount": "0.0000" }

            var exdata = { scale: '60', 'code': 'sh000001' }

            funcj2s.transform({
                conf: {
                    "host": "120.48.125.223",
                    "user": "root",
                    "password": "jiangshan",
                    "port": 53306,
                    "database": "pkuquant"
                },
                table: 'k_line_data',
                data: ouputs,
                exdata: exdata
            });
        });
    });
}

demo()

